#include "OLED.h"

void I2cWriteByte(uint8_t address, uint8_t byte)
{
    uint8_t buffer[2] = {address, byte};
    WifiIotI2cData I2cData = {0};
    I2cData.sendBuf = buffer;
    I2cData.sendLen = sizeof(buffer)/sizeof(uint8_t);
    I2cWrite(WIFI_IOT_I2C_IDX_1, OLED_ADDRESS , &I2cData);
}

void OLED_WriteCommand(uint8_t command)
{
    I2cWriteByte(0x00, command);
}

void OLED_WriteData(uint8_t data)
{
    I2cWriteByte(0x40, data);
}

const uint8_t OLED_F8x16[] = {
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//  0
	
	0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
	
	0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
	
	0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,
	0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
	
	0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,
	0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
	
	0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,
	0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
	
	0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,
	0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
	
	0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
	
	0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,
	0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
	
	0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,
	0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
	
	0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,
	0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
	
	0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,
	0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
	
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
	
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
	
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
	
	0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,
	0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
	
	0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
	0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
	
	0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,
	0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
	
	0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,
	0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
	
	0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,
	0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
	
	0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,
	0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
	
	0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,
	0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
	
	0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,
	0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
	
	0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,
	0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
	
	0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,
	0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
	
	0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
	0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
	
	0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,
	0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
	
	0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,
	0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
	
	0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,
	0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
	
	0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,
	0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
	
	0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,
	0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
	
	0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,
	0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
	
	0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,
	0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
	
	0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,
	0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
	
	0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,
	0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
	
	0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,
	0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
	
	0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,
	0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
	
	0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,
	0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
	
	0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,
	0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
	
	0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,
	0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
	
	0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,
	0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
	
	0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,
	0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
	
	0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,
	0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
	
	0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,
	0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
	
	0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,
	0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
	
	0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,
	0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
	
	0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,
	0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
	
	0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,
	0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
	
	0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,
	0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
	
	0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,
	0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
	
	0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,
	0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
	
	0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,
	0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
	
	0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,
	0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
	
	0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,
	0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
	
	0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,
	0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
	
	0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,
	0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
	
	0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,
	0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
	
	0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,
	0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
	
	0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,
	0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
	
	0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,
	0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
	
	0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60
	
	0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,
	0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
	
	0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
	
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
	
	0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
	
	0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
	0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
	
	0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,
	0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
	
	0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,
	0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
	
	0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,
	0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
	
	0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
	0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
	
	0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,
	0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
	
	0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,
	0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
	
	0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,
	0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
	
	0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,
	0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
	
	0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,
	0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
	
	0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,
	0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
	
	0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,
	0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
	
	0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
	0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
	
	0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,
	0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
	
	0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
	0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
	
	0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,
	0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
	
	0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,
	0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
	
	0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,
	0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
	
	0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,
	0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
	
	0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,
	0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
	
	0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,
	0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
	
	0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,
	0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
	
	0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,
	0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
	
	0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,
	0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
	
	0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,
	0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
	
	0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
	0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
	
	0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,
	0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
	
	0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
	
	0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,
	0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
	
	0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
};

/**
  * @brief  OLED设置光标位置
  * @param  Y 以左上角为原点，向下方向的坐标，范围：0~7
  * @param  X 以左上角为原点，向右方向的坐标，范围：0~127
  * @retval 无
  */
void OLED_SetCursor(uint8_t Y, uint8_t X)
{
	OLED_WriteCommand(0xB0 | ((Y)));				//设置Y位置
	OLED_WriteCommand(0x10 | ((X & 0xF0) >> 4));	//设置X位置低4位
	OLED_WriteCommand(0x00 | ((X & 0x0F)));			//设置X位置高4位
}

/**
  * @brief  OLED清屏
  * @param  无
  * @retval 无
  */
void OLED_Clear(void)
{
	for (uint8_t j = 0; j < 8; j++)
	{
		OLED_SetCursor(j, 0);
		for(uint8_t i = 0; i < 128; i++)
		{
			OLED_WriteData(0x00);
		}
	}
}

/**
  * @brief  OLED显示一个字符
  * @param  Row 行位置，范围：1~4
  * @param  Column 列位置，范围：1~16
  * @param  Character 要显示的一个字符，范围：ASCII可见字符
  * @retval 无
  */
void OLED_ShowCharacter(uint8_t Row, uint8_t Column, char Character)
{
	OLED_SetCursor((Row - 1) * 2, (Column - 1) * 8);			    //设置光标位置在上半部分
	for (uint8_t i = 0; i < 8; i++)
	{
		OLED_WriteData(OLED_F8x16[(Character - ' ')*16 + i]);	    //显示上半部分内容
	}
	OLED_SetCursor((Row - 1) * 2 + 1, (Column - 1) * 8);		    //设置光标位置在下半部分
	for (uint8_t i = 0; i < 8; i++)
	{
		OLED_WriteData(OLED_F8x16[(Character - ' ')*16 + i + 8]);   //显示下半部分内容
	}
}

/**
  * @brief  OLED显示字符串
  * @param  Row 起始行位置，范围：1~4
  * @param  Column 起始列位置，范围：1~16
  * @param  String 要显示的字符串，范围：ASCII可见字符
  * @retval 无
  */
void OLED_ShowString(uint8_t Row, uint8_t Column, char *String)
{
	uint8_t i;
	for (i = 0; String[i] != '\0'; i++)
	{
		OLED_ShowCharacter(Row, Column + i, String[i]);
	}
}

typedef struct
{
	char Index[3];	
	char Mask[32];
}GB16; 

//宋体
//16*16大小
//逐行式，顺向（高位在前）
const GB16 OLED_F16x16[] = 
{
	{"余",{0x80,0x80,0x40,0x20,0x50,0x48,0x44,0xC3,0x44,0x48,0x50,0x20,0x40,0x80,0x80,0x00,0x00,0x40,0x22,0x1A,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x0A,0x12,0x60,0x00,0x00}},
	{"伟",{0x00,0x80,0x60,0xF8,0x07,0x08,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0x08,0x00,0x01,0x00,0x00,0xFF,0x00,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x12,0x22,0x1E,0x00}},
	{"正",{0x00,0x02,0x02,0xC2,0x02,0x02,0x02,0xFE,0x82,0x82,0x82,0x82,0x82,0x02,0x00,0x00,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00}},
	{"在",{0x08,0x08,0x88,0xC8,0x38,0x0C,0x0B,0x08,0x08,0xE8,0x08,0x08,0x08,0x08,0x08,0x00,0x02,0x01,0x00,0xFF,0x40,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x00}},
	{"初",{0x08,0x08,0x89,0xEA,0x18,0x88,0x00,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x00,0x00,0x02,0x01,0x00,0xFF,0x01,0x86,0x40,0x20,0x18,0x07,0x40,0x80,0x40,0x3F,0x00,0x00}},
	{"始",{0x10,0x10,0xF0,0x1F,0x10,0xF0,0x00,0x40,0xE0,0x58,0x47,0x40,0x50,0x60,0xC0,0x00,0x40,0x22,0x15,0x08,0x16,0x21,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0xFE,0x00,0x00}},
	{"化",{0x00,0x80,0x60,0xF8,0x07,0x00,0x00,0x00,0xFF,0x40,0x20,0x10,0x08,0x04,0x00,0x00,0x01,0x00,0x00,0xFF,0x00,0x04,0x02,0x01,0x3F,0x40,0x40,0x40,0x40,0x40,0x78,0x00}},
	{"中",{0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00,0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,0x00}},
	{"大",{0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x80,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x03,0x0C,0x10,0x20,0x40,0x80,0x80,0x00}},
	{"气",{0x20,0x10,0x4C,0x47,0x54,0x54,0x54,0x54,0x54,0x54,0x54,0xD4,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x30,0x40,0xF0,0x00}},
	{"温",{0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00}},
	{"湿",{0x10,0x60,0x02,0x8C,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,0x04,0x04,0x7E,0x01,0x44,0x48,0x50,0x7F,0x40,0x40,0x7F,0x50,0x48,0x44,0x40,0x00}},
	{"光",{0x40,0x40,0x42,0x44,0x58,0xC0,0x40,0x7F,0x40,0xC0,0x50,0x48,0x46,0x40,0x40,0x00,0x80,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x78,0x00}},
	{"照",{0x00,0xFE,0x42,0x42,0x42,0xFE,0x00,0x42,0xA2,0x9E,0x82,0xA2,0xC2,0xBE,0x00,0x00,0x80,0x6F,0x08,0x08,0x28,0xCF,0x00,0x00,0x2F,0xC8,0x08,0x08,0x28,0xCF,0x00,0x00}},
	{"压",{0x00,0x00,0xFE,0x02,0x82,0x82,0x82,0x82,0xFA,0x82,0x82,0x82,0x82,0x82,0x02,0x00,0x80,0x60,0x1F,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x44,0x58,0x40,0x40,0x00}},
	{"强",{0x02,0xE2,0x22,0x22,0x3E,0x00,0x80,0x9E,0x92,0x92,0xF2,0x92,0x92,0x9E,0x80,0x00,0x00,0x43,0x82,0x42,0x3E,0x40,0x47,0x44,0x44,0x44,0x7F,0x44,0x44,0x54,0xE7,0x00}},
	{"度",{0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00}},
	{"土",{0x00,0x00,0x40,0x40,0x40,0x40,0x40,0xFF,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00}},
	{"壤",{0x10,0x10,0xFF,0x10,0x00,0x82,0xBA,0xEA,0xBA,0x83,0xBA,0xEA,0xBA,0x82,0x00,0x00,0x08,0x18,0x0F,0x04,0x48,0x4A,0x2A,0xFF,0x8A,0x4A,0x1A,0x2F,0x5A,0x8A,0x88,0x00}},
	{"烟",{0x80,0x70,0x00,0xFF,0x10,0x08,0xFE,0x42,0x42,0x42,0xFA,0x42,0x42,0x42,0xFE,0x00,0x80,0x60,0x18,0x07,0x08,0x10,0xFF,0x50,0x48,0x46,0x41,0x42,0x4C,0x40,0xFF,0x00}},
	{"雾",{0x10,0x0C,0x05,0x55,0x55,0xD5,0x05,0x7F,0x05,0x55,0x55,0x55,0x05,0x14,0x0C,0x00,0x10,0x10,0x10,0x8A,0xA9,0x6B,0x35,0x25,0x25,0xAB,0xE9,0x08,0x10,0x10,0x10,0x00}},
	{"浓",{0x10,0x60,0x02,0x8C,0x20,0x18,0x08,0xC8,0x38,0xCF,0x08,0x08,0x28,0x98,0x00,0x00,0x04,0x04,0x7E,0x01,0x04,0x02,0x01,0xFF,0x40,0x21,0x06,0x0A,0x11,0x20,0x40,0x00}},
	{"水",{0x00,0x20,0x20,0x20,0xA0,0x60,0x00,0xFF,0x60,0x80,0x40,0x20,0x18,0x00,0x00,0x00,0x20,0x10,0x08,0x06,0x01,0x40,0x80,0x7F,0x00,0x01,0x02,0x04,0x08,0x10,0x10,0x00}},
	{"域",{0x20,0x20,0xFF,0x20,0x20,0x08,0xC8,0x48,0x48,0xC8,0x08,0xFF,0x08,0x09,0xCA,0x00,0x10,0x30,0x1F,0x08,0x08,0x20,0x67,0x24,0x14,0x97,0x50,0x27,0x38,0x46,0xF1,0x00}},
	{"位",{0x00,0x80,0x60,0xF8,0x07,0x10,0x90,0x10,0x11,0x16,0x10,0x10,0xD0,0x10,0x00,0x00,0x01,0x00,0x00,0xFF,0x40,0x40,0x41,0x5E,0x40,0x40,0x70,0x4E,0x41,0x40,0x40,0x00}},
	{"高",{0x04,0x04,0x04,0x04,0xF4,0x94,0x95,0x96,0x94,0x94,0xF4,0x04,0x04,0x04,0x04,0x00,0x00,0xFE,0x02,0x02,0x7A,0x4A,0x4A,0x4A,0x4A,0x4A,0x7A,0x02,0x82,0xFE,0x00,0x00}},
	{"数",{0x90,0x52,0x34,0x10,0xFF,0x10,0x34,0x52,0x80,0x70,0x8F,0x08,0x08,0xF8,0x08,0x00,0x82,0x9A,0x56,0x63,0x22,0x52,0x8E,0x00,0x80,0x40,0x33,0x0C,0x33,0x40,0x80,0x00}},
	{"字",{0x10,0x0C,0x04,0x24,0x24,0x24,0x25,0x26,0xA4,0x64,0x24,0x04,0x04,0x14,0x0C,0x00,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00}},
	{"模",{0x10,0x10,0xD0,0xFF,0x90,0x14,0xE4,0xAF,0xA4,0xA4,0xA4,0xAF,0xE4,0x04,0x00,0x00,0x04,0x03,0x00,0xFF,0x00,0x89,0x4B,0x2A,0x1A,0x0E,0x1A,0x2A,0x4B,0x88,0x80,0x00}},
	{"拟",{0x10,0x10,0x10,0xFF,0x90,0x00,0xF8,0x00,0x02,0x04,0x18,0x00,0xFF,0x00,0x00,0x00,0x02,0x42,0x81,0x7F,0x00,0x00,0x3F,0x10,0x88,0x40,0x30,0x0C,0x0B,0x30,0xC0,0x00}},
	{"量",{0x20,0x20,0x20,0xBE,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xBE,0x20,0x20,0x20,0x00,0x00,0x80,0x80,0xAF,0xAA,0xAA,0xAA,0xFF,0xAA,0xAA,0xAA,0xAF,0x80,0x80,0x00,0x00}},
	{"据",{0x10,0x10,0xFF,0x10,0x90,0x00,0xFE,0x92,0x92,0x92,0xF2,0x92,0x92,0x9E,0x80,0x00,0x42,0x82,0x7F,0x01,0x80,0x60,0x1F,0x00,0xFC,0x44,0x47,0x44,0x44,0xFC,0x00,0x00}},
	{"连",{0x40,0x40,0x42,0xCC,0x00,0x04,0x44,0x64,0x5C,0x47,0xF4,0x44,0x44,0x44,0x04,0x00,0x00,0x40,0x20,0x1F,0x20,0x44,0x44,0x44,0x44,0x44,0x7F,0x44,0x44,0x44,0x44,0x00}},
	{"接",{0x10,0x10,0x10,0xFF,0x10,0x50,0x44,0x54,0x65,0xC6,0x44,0x64,0x54,0x44,0x40,0x00,0x04,0x44,0x82,0x7F,0x01,0x82,0x82,0x4A,0x56,0x23,0x22,0x52,0x4E,0x82,0x02,0x00}},
	{"成",{0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0x08,0x08,0xFF,0x08,0x09,0x0A,0xC8,0x08,0x00,0x80,0x60,0x1F,0x00,0x10,0x20,0x1F,0x80,0x40,0x21,0x16,0x18,0x26,0x41,0xF8,0x00}},
	{"功",{0x08,0x08,0x08,0xF8,0x08,0x08,0x08,0x10,0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00,0x10,0x30,0x10,0x1F,0x08,0x88,0x48,0x30,0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00}},
	{"版",{0x00,0xFE,0x20,0x20,0x3F,0x20,0x00,0xFC,0x24,0xE4,0x24,0x22,0x23,0xE2,0x00,0x00,0x80,0x7F,0x01,0x01,0xFF,0x80,0x60,0x1F,0x80,0x41,0x26,0x18,0x26,0x41,0x80,0x00}},
	{"权",{0x10,0x10,0xD0,0xFF,0x90,0x10,0x02,0x1E,0xE2,0x02,0x02,0x02,0xE2,0x1E,0x00,0x00,0x04,0x03,0x00,0xFF,0x00,0x83,0x80,0x40,0x20,0x13,0x0C,0x13,0x20,0x40,0x80,0x00}},
	{"归",{0x00,0xFC,0x00,0x00,0xFF,0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0xFC,0x00,0x00,0x00,0x87,0x40,0x30,0x0F,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7F,0x00,0x00}},
	{"所",{0x00,0x00,0xFC,0x24,0x24,0x22,0xE3,0x02,0xFC,0x44,0x44,0x42,0xC3,0x42,0x40,0x00,0x40,0x30,0x0F,0x02,0x02,0x82,0x43,0x30,0x0F,0x00,0x00,0x00,0xFF,0x00,0x00,0x00}},
	{"有",{0x04,0x04,0x04,0x84,0xE4,0x3C,0x27,0x24,0x24,0x24,0x24,0xE4,0x04,0x04,0x04,0x00,0x04,0x02,0x01,0x00,0xFF,0x09,0x09,0x09,0x09,0x49,0x89,0x7F,0x00,0x00,0x00,0x00}},
	{"制",{0x40,0x50,0x4E,0x48,0x48,0xFF,0x48,0x48,0x48,0x40,0xF8,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x3E,0x02,0x02,0xFF,0x12,0x22,0x1E,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00}},
	{"作",{0x00,0x80,0x60,0xF8,0x07,0x40,0x30,0x0F,0xF8,0x88,0x88,0x88,0x88,0x08,0x08,0x00,0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0xFF,0x08,0x08,0x08,0x08,0x08,0x00,0x00}},
	{"原",{0x00,0x00,0xFE,0x02,0x02,0xF2,0x92,0x9A,0x96,0x92,0x92,0xF2,0x02,0x02,0x02,0x00,0x80,0x60,0x1F,0x40,0x20,0x17,0x44,0x84,0x7C,0x04,0x04,0x17,0x20,0x40,0x00,0x00}},
	{"创",{0x40,0x20,0xD0,0x4C,0x43,0x44,0xC8,0x10,0x20,0x00,0xF8,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x3F,0x40,0x44,0x48,0x47,0x40,0x70,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00}},
	{"毕",{0x00,0x00,0xFF,0x88,0x88,0x48,0x48,0x00,0x7F,0x88,0x84,0x84,0x82,0xE0,0x00,0x00,0x04,0x04,0x05,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00}},
	{"℃",{0x06,0x09,0x09,0xE6,0xF8,0x0C,0x04,0x02,0x02,0x02,0x02,0x02,0x04,0x1E,0x00,0x00,0x00,0x00,0x00,0x07,0x1F,0x30,0x20,0x40,0x40,0x40,0x40,0x40,0x20,0x10,0x00,0x00}},
};
/**
  * @brief  OLED显示汉字
  * @param  Row 起始行位置，范围：1~4
  * @param  Column 起始列位置，范围：1~16
  * @param  CH 要显示的数字，范围：前文OLED_F16x16内部定义的汉字
  * @retval 无
  */
void OLED_ShowChinese(uint8_t Row, uint8_t Column, char *CH)
{      			    
	uint8_t i,j,k,n = 0;
	char *p = CH;
	while (*p++ != '\0')
	{
		n ++;
	}
	for(k = 0; k < n; k +=3)
	{
		for(i = 0; i < sizeof(OLED_F16x16)/sizeof(GB16); i ++)
		{
			if((OLED_F16x16[i].Index[0] == CH[k]) && (OLED_F16x16[i].Index[1] == CH[k+1]) && (OLED_F16x16[i].Index[2] == CH[k+2]))
			{
				OLED_SetCursor((Row - 1) * 2, (Column - 1) * 8 + 8 * 2*k/3);		//设置光标位置在上半部分
				for (j = 0; j < 16; j ++)
				{
					OLED_WriteData(OLED_F16x16[i].Mask[j]);						//显示上半部分内容
				}
				OLED_SetCursor((Row - 1) * 2 + 1, (Column - 1) * 8 + 8 * 2*k/3);	//设置光标位置在下半部分
				for (j = 0; j < 16; j ++)
				{
					OLED_WriteData(OLED_F16x16[i].Mask[j + 16]);				//显示下半部分内容
				}
			}
		}
	}
}

/**
  * @brief  OLED次方函数
  * @retval 返回值等于X的Y次方
  */
uint32_t OLED_Pow(uint32_t X, uint32_t Y)
{
	uint32_t Result = 1;
	while (Y--)
	{
		Result *= X;
	}
	return Result;
}

/**
  * @brief  OLED显示数字（十进制，正数）
  * @param  Row 起始行位置，范围：1~4
  * @param  Column 起始列位置，范围：1~16
  * @param  Integer 要显示的数字，范围：0~4294967295
  * @param  Length 要显示数字的长度，范围：1~10
  * @retval 无
  */
void OLED_ShowInteger(uint8_t Row, uint8_t Column, uint32_t Integer, uint8_t Length)
{
	uint8_t i;
	for (i = 0; i < Length; i++)							
	{
		OLED_ShowCharacter(Row, Column + i, Integer / OLED_Pow(10, Length - i - 1) % 10 + '0');
	}
}

/**
  * @brief  OLED显示数字（十进制，带符号数）
  * @param  Row 起始行位置，范围：1~4
  * @param  Column 起始列位置，范围：1~16
  * @param  Integer 要显示的数字，范围：-2147483648~2147483647
  * @param  Length 要显示数字的长度，范围：1~10
  * @retval 无
  */
void OLED_ShowSignedInteger(uint8_t Row, uint8_t Column, int Integer, uint8_t Length)
{
	uint8_t i;
	uint32_t Integer1;
	if (Integer >= 0)
	{
		OLED_ShowCharacter(Row, Column, '+');
		Integer1 = Integer;
	}
	else
	{
		OLED_ShowCharacter(Row, Column, '-');
		Integer1 = -Integer;
	}
	for (i = 0; i < Length; i++)							
	{
		OLED_ShowCharacter(Row, Column + i + 1, Integer1 / OLED_Pow(10, Length - i - 1) % 10 + '0');
	}
}

/**
  * @brief  OLED显示数字（十六进制，正数）
  * @param  Row 起始行位置，范围：1~4
  * @param  Column 起始列位置，范围：1~16
  * @param  Integer 要显示的数字，范围：0~0xFFFFFFFF
  * @param  Length 要显示数字的长度，范围：1~8
  * @retval 无
  */
void OLED_ShowHexInteger(uint8_t Row, uint8_t Column, uint32_t Integer, uint8_t Length)
{
	uint8_t i,SingleInteger;
	OLED_ShowCharacter(Row, Column + 0, '0');
	OLED_ShowCharacter(Row, Column + 1, 'x');
	for (i = 0; i < Length; i++)							
	{
		SingleInteger = Integer / OLED_Pow(16, Length - i - 1) % 16;
		if (SingleInteger < 10)
		{
			OLED_ShowCharacter(Row, Column + i + 2, SingleInteger + '0');
		}
		else
		{
			OLED_ShowCharacter(Row, Column + i + 2, SingleInteger - 10 + 'A');
		}
	}
}

/**
  * @brief  OLED显示数字（二进制，正数）
  * @param  Row 起始行位置，范围：1~4
  * @param  Column 起始列位置，范围：1~16
  * @param  Integer 要显示的数字，范围：0~1111 1111 1111 1111
  * @param  Length 要显示数字的长度，范围：1~16
  * @retval 无
  */
void OLED_ShowBinInteger(uint8_t Row, uint8_t Column, uint32_t Integer, uint8_t Length)
{
	uint8_t i;
	for (i = 0; i < Length; i++)							
	{
		OLED_ShowCharacter(Row, Column + i, Integer / OLED_Pow(2, Length - i - 1) % 2 + '0');
	}
}

/**
  * @brief  OLED显示浮点数
  * @param  Row 起始行位置，范围：1~4
  * @param  Column 起始列位置，范围：1~16
  * @param  Number 要显示的数字，范围：-999.99~+999.99
  * @param  LengthOfIntegralPart 要显示整数部分的长度，范围：3~1
  * @param  LengthOfDecimalPart 要显示小数部分的长度，范围：0~2
  * @retval 无
  */
void OLED_ShowSignedFloat(uint8_t Row, uint8_t Column, float Number, uint8_t LengthOfIntegralPart, uint8_t LengthOfDecimalPart)
{
	float AbsoluteValue = Number >= 0 ? Number : -Number;
	uint32_t i2,i1,i0,f1,f2;
	i2 = (uint32_t)AbsoluteValue % 1000 / 100;						//求百位
	i1 = (uint32_t)AbsoluteValue % 100 / 10;						    //求十位
	i0 = (uint32_t)AbsoluteValue % 10 / 1;   						//求个位
	f1 = ((AbsoluteValue-(uint32_t)AbsoluteValue))*10;				//求小数点后一位
	f2 = (uint32_t)((AbsoluteValue-(uint32_t)AbsoluteValue)*100)%10;      //求小数点后两位
	
	if(Number > 0)
	{
		OLED_ShowCharacter(Row, Column, '+');
	}
	else if(Number < 0)
	{
		OLED_ShowCharacter(Row, Column, '-');
	}
	else
	{
		OLED_ShowCharacter(Row, Column, ' ');
	}
	if(LengthOfIntegralPart == 1)
	{
		if(LengthOfDecimalPart == 0)
		{
			OLED_ShowInteger(Row, Column + 1, i0 ,1);
		}
		else if(LengthOfDecimalPart == 1)
		{
			OLED_ShowInteger(Row, Column + 1, i0 ,1);
			OLED_ShowCharacter(Row, Column + 2, '.');
			OLED_ShowInteger(Row, Column + 3, f1 ,1);
		}
		else
		{
			OLED_ShowInteger(Row, Column + 1, i0 ,1);
			OLED_ShowCharacter(Row, Column + 2, '.');
			OLED_ShowInteger(Row, Column + 3, f1 ,1);
			OLED_ShowInteger(Row, Column + 4, f2 ,1);
		}
	}
	else if(LengthOfIntegralPart == 2)
	{
		if(LengthOfDecimalPart == 0)
		{
			OLED_ShowInteger(Row, Column + 1, i1 ,1);
			OLED_ShowInteger(Row, Column + 2, i0 ,1);
		}
		else if(LengthOfDecimalPart == 1)
		{
			OLED_ShowInteger(Row, Column + 1, i1 ,1);
			OLED_ShowInteger(Row, Column + 2, i0 ,1);
			OLED_ShowCharacter(Row, Column + 3, '.');
			OLED_ShowInteger(Row, Column + 4, f1 ,1);
		}
		else
		{
			OLED_ShowInteger(Row, Column + 1, i1 ,1);
			OLED_ShowInteger(Row, Column + 2, i0 ,1);
			OLED_ShowCharacter(Row, Column + 3, '.');
			OLED_ShowInteger(Row, Column + 4, f1 ,1);
			OLED_ShowInteger(Row, Column + 5, f2 ,1);
		}
	}
	else
	{
		if(LengthOfDecimalPart == 0)
		{
			OLED_ShowInteger(Row, Column + 1, i2 ,1);
			OLED_ShowInteger(Row, Column + 2, i1 ,1);
			OLED_ShowInteger(Row, Column + 3, i0 ,1);
		}
		else if(LengthOfDecimalPart == 1)
		{
			OLED_ShowInteger(Row, Column + 1, i2 ,1);
			OLED_ShowInteger(Row, Column + 2, i1 ,1);
			OLED_ShowInteger(Row, Column + 3, i0 ,1);
			OLED_ShowCharacter(Row, Column + 4, '.');
			OLED_ShowInteger(Row, Column + 5, f1 ,1);
		}
		else
		{
			OLED_ShowInteger(Row, Column + 1, i2 ,1);
			OLED_ShowInteger(Row, Column + 2, i1 ,1);
			OLED_ShowInteger(Row, Column + 3, i0 ,1);
			OLED_ShowCharacter(Row, Column + 4, '.');
			OLED_ShowInteger(Row, Column + 5, f1 ,1);
			OLED_ShowInteger(Row, Column + 6, f2 ,1);
		}
	}		
}

void OLED_Init(void)
{
    GpioInit();
    IoSetFunc(WIFI_IOT_IO_NAME_GPIO_0, WIFI_IOT_IO_FUNC_GPIO_0_I2C1_SDA);
    IoSetFunc(WIFI_IOT_IO_NAME_GPIO_0, WIFI_IOT_IO_FUNC_GPIO_1_I2C1_SCL);
    I2cInit(WIFI_IOT_GPIO_IDX_1, 40000);
	//上电延时
	for (uint32_t i = 0; i < 1000; i++)
	{
		for (uint32_t j = 0; j < 1000; j++);
	}

    OLED_WriteCommand(0xAE);	//关闭显示	
	OLED_WriteCommand(0xD5);	//设置显示时钟分频比/振荡器频率
	OLED_WriteCommand(0x80);	
	OLED_WriteCommand(0xA8);	//设置多路复用率
	OLED_WriteCommand(0x3F);	
	OLED_WriteCommand(0xD3);	//设置显示偏移
	OLED_WriteCommand(0x00);	
	OLED_WriteCommand(0x40);	//设置显示开始行	
	OLED_WriteCommand(0xA1);	//设置左右方向，0xA1正常 0xA0左右反置	
	OLED_WriteCommand(0xC8);	//设置上下方向，0xC8正常 0xC0上下反置
	OLED_WriteCommand(0xDA);	//设置COM引脚硬件配置
	OLED_WriteCommand(0x12);	
	OLED_WriteCommand(0x81);	//设置对比度控制
	OLED_WriteCommand(0xCF);
	OLED_WriteCommand(0xD9);	//设置预充电周期
	OLED_WriteCommand(0xF1);
	OLED_WriteCommand(0xDB);	//设置VCOMH取消选择级别
	OLED_WriteCommand(0x30);
	OLED_WriteCommand(0xA4);	//设置整个显示打开/关闭
	OLED_WriteCommand(0xA6);	//设置正常/倒转显示
	OLED_WriteCommand(0x8D);	//设置充电泵
	OLED_WriteCommand(0x14);
	OLED_WriteCommand(0xAF);	//开启显示

	OLED_Clear();				//OLED清屏
}
